package org.example.controller;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.example.dao.DemoMapper;
import org.example.service.DemoService;
import org.example.service.ExportPdf;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;

@RestController
@RequestMapping("/demo")
public class DemoController {
    @Resource
    private DemoService service;

    @RequestMapping(value = "/hello", method = {RequestMethod.GET, RequestMethod.POST})
    public String hello() {
        return "hello";
    }

    @RequestMapping(value = "/addDevice", method = {RequestMethod.GET, RequestMethod.POST})
    public String addDevice() {
        service.addDevice();
        return "success";
    }

    @RequestMapping(value = "/addDeviceData", method = {RequestMethod.GET, RequestMethod.POST})
    public String addDeviceData(String start, String end) {
        service.addDeviceData(start, end);
        service.addDeviceStatsData(start, end);
        service.addDeviceReportData(start, end);
        return "success";
    }

    @RequestMapping(value = "/test", method = {RequestMethod.GET, RequestMethod.POST})
    public String test() {
        return "success";
    }


    @Resource
    private ExportPdf exportPdf;
    @RequestMapping(value = "/export", method = {RequestMethod.GET, RequestMethod.POST})
    public String export() throws IOException, InvalidFormatException {
        exportPdf.export();
        return "success";
    }
}
